#include <iostream>
#include "camserver.h"
#include "readthread.h"

#define WAIT_FOR_NEW_FRAME 33

using namespace std;

ReadThread::ReadThread(CameraServer * server)
: wxThread() {
	this->server = server;
}

void * ReadThread::Entry() {
	IplImage * frame = 0;
	while (!this->TestDestroy()) {
		Sleep(WAIT_FOR_NEW_FRAME);
		wxCriticalSectionLocker open(this->server->protectFrameCS);
		frame = cvQueryFrame(this->server->getCapture());
		if (!frame) continue;
		this->server->setCurrentFrame(frame);
	}
	return 0;
}

void ReadThread::OnExit() {

}
